myApp.factory("currentlyTrendingService",function($http, $q, $cookies) {
   
    return {
        getCurrentlyTrending : getCurrentlyTrending,
        getSimilarDisheshFromOtherChefs : getSimilarDisheshFromOtherChefs,
        getMostPopularDishesFromChef : getMostPopularDishesFromChef
    };
   
    function getCurrentlyTrending(mealId){
        var deferred = $q.defer();
        var userCookie = JSON.parse($cookies.userCookie);
        return $http({
            method : 'GET',
            url    : 'api/latesttrending/' + mealId,
            headers: {
                'username': userCookie.name,
                'usertype': userCookie.type
            }
        }).success(function(respData) {
            deferred.resolve(respData);			
        }).error(function(errorData) {
            console.log("Error while retriving users. Error: " + errorData.ex );
        //commonService.showErrorMessage(errorData ,"Error while receiving project details.");
        });
        return deferred.promise;
    };
    
    
    function getSimilarDisheshFromOtherChefs(mealId){
        var deferred = $q.defer();
        var userCookie = JSON.parse($cookies.userCookie);
        return $http({
            method : 'GET',
            url    : 'api/latesttrending/' + mealId,
            headers: {
                'username': userCookie.name,
                'usertype': userCookie.type
            }
        }).success(function(respData) {
            deferred.resolve(respData);			
        }).error(function(errorData) {
            console.log("Error while retriving users. Error: " + errorData.ex );
        //commonService.showErrorMessage(errorData ,"Error while receiving project details.");
        });
        return deferred.promise;
    };
    
    function getMostPopularDishesFromChef(mealId){
        var deferred = $q.defer();
        var userCookie = JSON.parse($cookies.userCookie);
        return $http({
            method : 'GET',
            url    : 'api/populardishes/' + mealId,
            headers: {
                'username': userCookie.name,
                'usertype': userCookie.type
            }
        }).success(function(respData) {
            deferred.resolve(respData);			
        }).error(function(errorData) {
            console.log("Error while retriving users. Error: " + errorData.ex );
        //commonService.showErrorMessage(errorData ,"Error while receiving project details.");
        });
        return deferred.promise;
    };
});